var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var UserView = (function (_super) {
    __extends(UserView, _super);
    function UserView() {
        _super.apply(this, arguments);

    }
    UserView.prototype.Ready = function () {
        $.templates({
            WorkItemTemplate: "<a href='{{:Url}}' target='_blank' data-content='{{:Content}}'>{{:Title}}</a>&nbsp;&nbsp;",
            TimeLineTemplate: "#NTimeLineTemplate"
        });
        this.SetUserMainKPI();
        this.SetBugsHistory();
        this.SetTasksHistory();
        this.SetUserHistory();
        var _self = this;
        $('a[data-action]').click(function () {
            var action = $(this).attr('data-action');
            CallService('POST', _self.aUrl[4], {
                id: _self.options.userId,
                type: action
            }, true, function () {
                window.location.reload();
            });
        });
    };
    UserView.prototype.SetUserMainKPI = function () {
        var _this = this;
        $.getJSON(this.aUrl[0], {
            id: this.options.userId
        }, function (data) {
            if(data) {
                _this.SetWorkItemLine(data.UserStories, "#imgldw", "#wip");
                _this.SetWorkItemLine(data.Tasks, "#imglts", "#lts");
                _this.SetWorkItemLine(data.Bugs, "#imglbg", "#lbg");
                _this.SetWorkItemLine(data.CheckOuts, "#imgldp", "#pcs");
                $("#kpiScore").html(data.Score);
                $("#kpiHours").html(data.Hours);
                $("#kpiBugs").html(data.Fixedbugs);
                $("#kpiTasks").html(data.TotalTasks);
            }
            window.setTimeout(function () {
                return _this.SetUserMainKPI();
            }, 240000);
        });
    };
    UserView.prototype.SetBugsHistory = function () {
        var _this = this;
        $.getJSON(this.aUrl[1], {
            id: this.options.userId
        }, function (data) {
            if(data) {
                _this.InitGraph(data, null, null, null, 'grphBugs', 'Bugs History', 250, false);
                window.setTimeout(function () {
                    return _this.SetBugsHistory();
                }, 240000);
            }
        });
    };
    UserView.prototype.SetTasksHistory = function () {
        var _this = this;
        $.getJSON(this.aUrl[2], {
            id: this.options.userId
        }, function (data) {
            if(data && data.Item1 && data.Item2 && data.Item3) {
                _this.InitGraph(data.Item1, null, null, null, 'grphHours', 'Completed Hours', 250, false);
                _this.InitGraph(data.Item2, null, null, null, 'grphTasks', 'Done Tasks', 250, false);
                window.setTimeout(function () {
                    return _this.SetTasksHistory();
                }, 300000);
            }
        });
    };
    UserView.prototype.SetUserHistory = function () {
        var _this = this;
        $.getJSON(this.aUrl[3], {
            id: this.options.userId
        }, function (data) {
            if(data) {
                var lenght = data.length;
                var dateArray = new Array();
                for(var index = 0; index < lenght; index++) {
                    var converDate = new Date(parseInt(data[index].Date.substr(6)));
                    data[index].Date = converDate;
                    data[index].SmallDate = converDate.toISOString();
                    var ISODate = converDate.toISOString().substr(0, 10);
                    var indexOfElem = _this.arrayObjectIndexOf(dateArray, ISODate, "ISODate");
                    if(indexOfElem == -1) {
                        indexOfElem = dateArray.push({
                            ISODate: ISODate,
                            CompleteDate: converDate.toLocaleDateString(),
                            data: new Array()
                        }) - 1;
                    }
                    dateArray[indexOfElem].data.push(data[index]);
                }
                var content = $.render.TimeLineTemplate(dateArray);
                $("#timeline-container").html(content);
                $('abbr.timeago').timeago();
                window.setTimeout(function () {
                    return _this.SetUserHistory();
                }, 360000);
            }
        });
    };
    UserView.prototype.SetWorkItemLine = function (data, imgName, elementName) {
        var content = "<em>No work item</em>";
        if(data && data.length > 0) {
            content = $.render.WorkItemTemplate(data);
        }
        $(imgName).hide();
        $(elementName).empty().append(content);
    };
    UserView.prototype.arrowPoints = function (containerName) {
        var s = $(containerName).find('.item');
        $.each(s, function (index, obj) {
            var myObj = $(obj);
            if(index % 2 == 1) {
                myObj.addClass('item-right');
            }
            var posLeft = myObj.css("left");
            var html = posLeft == "0px" ? 'rightCorner' : 'leftCorner';
            html = "<span class='" + html + "'></span>";
            myObj.prepend(html);
        });
    };
    UserView.prototype.InitGraph = function (serie1, serie2, serie1Name, serie2Name, renderName, title, height, smallLabel) {
        var series = Array();
        if(serie1) {
            series.push({
                name: serie1Name,
                data: serie1
            });
        }
        if(serie2) {
            series.push({
                name: serie2Name,
                data: serie2
            });
        }
        if(series && series.length > 0) {
            var legend = series.length > 1;
            var xAxis = {
                categories: [
                    'D-6', 
                    'D-5', 
                    'D-4', 
                    'D-3', 
                    'D-2', 
                    'D-1', 
                    'Today'
                ],
                labels: {
                    rotation: -45,
                    align: 'right'
                }
            };
            var myTitle = {
                text: title
            };
            if(smallLabel) {
                xAxis.labels.style = {
                    fontSize: '8px'
                };
                myTitle.style = {
                    fontSize: '14px'
                };
            }
            this.bdgchart = new Highcharts.Chart({
                chart: {
                    renderTo: renderName,
                    height: height,
                    borderRadius: 0,
                    backgroundColor: '#FFF',
                    type: 'column'
                },
                legend: {
                    enabled: legend
                },
                credits: {
                    enabled: false
                },
                colors: [
                    '#1570A6', 
                    '#E23300'
                ],
                xAxis: xAxis,
                yAxis: {
                    min: 0,
                    title: {
                        text: null
                    }
                },
                title: myTitle,
                series: series
            });
        }
    };
    return UserView;
})(Base.Page);
//@ sourceMappingURL=UserView.js.map
